package cn.arnold.offer.spdb;
import java.util.*;
/**
 * @Author Arnold
 * @Desc 约瑟夫问题
 **/
public class Main{
    public static void main (String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i< n; i++){
            list.add(i);
        }
        int index = -1;
        while(list.size()>1){
            index = (index+4)%list.size();
            list.remove(index);
            index--;
        }
        System.out.println(list.get(0));
    }
}
